;;; Power digit sum

;;; Problem 16

;;; 2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6
;;; + 8 = 26.

;;; What is the sum of the digits of the number 2^1000?

;; IDEA 1: Maybe the supposed problem is, that 2 to the
;; power of 1000 is a too large number for some programming
;; languages, to contain in their standard number types?

;; IDEA 2: Maybe the supposed problem is, that
;; exponentiating by 1000 takes a long time? Maybe the idea
;; is to use fast exponentiation?

;; IDEA 3: Maybe there is a pattern in the digits sum
;; depending on the exponent?

;; 0 -> 1 (double)
;; 1 -> 2 (double)
;; 2 -> 4 (double)
;; 3 -> 8 (double)
;; 4 -> 7 (minus 1)
;; 5 -> 5 (minus 2)
;; 6 -> 10 (double)
;; 7 -> 11 (plus 1)
;; 8 -> 13 (plus 2)
;; 9 -> 8 (minus 5)
;; 10 -> 7 (minus 1)

(import
 (except (rnrs base) let-values map)
 (only (guile)
       lambda* λ
       ;; printing
       display
       simple-format)
 (lib math))


;; Alright, just gonna calculate it in a naive way. No idea
;; what insight I am missing out on.
(display
 (simple-format
  #f "~a\n"
  (digits-sum (expt 2 1000))))
